import React from 'react'
import {useState} from "react"
import Myevents from "../utils/events"
import Grandson from './grandson';
function Appson(props) {
    console.log(props,"11111");
    let [arr,setArr] = useState([
       "选项一","选项2","选项3"
    ])
    let [flag,setFlag] = useState(true)
    let fn = ()=>{
        setFlag(!flag)
    }
    let fn1 = ()=>{
      props.fn("aaaa")
    }
    let sendclass = ()=>{
      Myevents.emit("fn","我是传给兄弟组件的数据") // 第一个参数，兄弟组件需要监听的名字 第二个参数，要传递的数据
    }
  return (
    <div>
          <hr></hr>
          <h1>{props.send}</h1>
          <h1>{props.name}</h1>
          <button onClick={fn1}>点我给父组件传参</button>
          <div className='btndiv' onClick={fn}>点击下拉</div>
          <div className={flag?"active":""}>
                {
              flag ? arr.map((item,index)=>{

                  return <p key={index}>{item}</p>
              }):""
             }
             <button onClick={sendclass}>点我给我给兄弟组件传参</button>
          </div>
          <hr />  
          <Grandson></Grandson>
         
    </div>
  
  )
}

export default Appson